package com.wsm.common.controller;

import com.wsm.common.annotation.DuplicateSubmitToken;
import com.wsm.common.annotation.OperateLog;
import com.wsm.common.business.ConfigBusiness;
import com.wsm.common.domain.ConfigDO;
import com.wsm.common.utils.PageUtils;
import com.wsm.common.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 系统配置信息表
 *
 * @author wangshimin
 * @email wangshiminhome@foxmail.com
 * @date 2020-02-14 17:43:18
 * @description : 系统配置信息表
 */
@Api(tags = "系统配置信息表")
@Controller
@RequestMapping("/common/config")
public class ConfigController {
	@Autowired
	private ConfigBusiness configBusiness;

	@GetMapping()
	@ApiOperation(value = "跳转展示界面")
	@RequiresPermissions("common:config:look")
	String Config() {
		return "common/config/config";
	}

	@ResponseBody
	@GetMapping("/list")
	@ApiOperation(value = "获取集合列表")
	@RequiresPermissions("common:config:look")
	public Result<PageUtils> list(@RequestParam Map<String, Object> params) {
		return configBusiness.list(params);
	}

	@GetMapping("/add")
	@ApiOperation(value = "跳转增加界面")
	@RequiresPermissions("common:config:add")
	String add() {
		return "common/config/add";
	}

	@GetMapping("/edit/{id}")
	@ApiOperation(value = "跳转修改界面")
	@RequiresPermissions("common:config:edit")
	String edit(@PathVariable("id") Long id, Model model) {
		ConfigDO config = configBusiness.get(id);
		model.addAttribute("config", config);
		return "common/config/edit";
	}

	/**
	 * 保存
	 */
	@OperateLog("增加系统配置信息表")
	@ResponseBody
	@PostMapping("/save")
	@DuplicateSubmitToken
	@ApiOperation(value = "增加")
	@RequiresPermissions("common:config:add")
	public Result save(ConfigDO config) {
		return configBusiness.save(config);
	}

	/**
	 * 修改
	 */
	@OperateLog("修改系统配置信息表")
	@ResponseBody
	@DuplicateSubmitToken
	@RequestMapping("/update")
	@ApiOperation(value = "修改")
	@RequiresPermissions("common:config:edit")
	public Result update(ConfigDO config) {
		return configBusiness.update(config);
	}

	/**
	 * 删除
	 */
	@OperateLog("删除系统配置信息表")
	@ResponseBody
	@DuplicateSubmitToken
	@PostMapping("/remove")
	@ApiOperation(value = "删除")
	@RequiresPermissions("common:config:remove")
	public Result remove(Long id) {
		return configBusiness.remove(id);
	}

	/**
	 * 删除
	 */
	@OperateLog("批量删除系统配置信息表")
	@ResponseBody
	@DuplicateSubmitToken
	@PostMapping("/batchRemove")
	@ApiOperation(value = "批量删除")
	@RequiresPermissions("common:config:batchRemove")
	public Result remove(@RequestParam("ids[]") Long[] ids) {
		return configBusiness.batchRemove(ids);
	}


	/**
	 * 修改可用状态
	 */
	@OperateLog("修改可用状态系统配置信息表")
	@ResponseBody
	@DuplicateSubmitToken
	@PostMapping("/changeStatus")
	@ApiOperation(value = "修改可用状态")
	@RequiresPermissions("common:config:change")
	public Result changeUseFlag(Long id, Integer status) {
		return configBusiness.updateUseFlag(id, status);
	}

}
